//logs.js
//获取应用实例
const school = require('../../../utils/school.js');
const app = getApp();

Page({
  data: {
    school: school,
    selectId:0,
    VerticalNavTop: 0,
    TabCur: 0,
    MainCur: 0,
    load:true,
    list: [],
    city:["北京","上海","黑龙江","吉林","辽宁","天津","安徽","江苏","浙江","湖北","广东","湖南","甘肃","四川","山西","山东","河南","福建","云南","重庆","江西","河北","贵州","陕西","内蒙古","广西","青海","宁夏","海南","新疆","西藏"]
  },
  onLoad: function () {

    console.log(this.data.school[this.data.selectId])

  },
  schoolSelect: function(dom){
    let school = dom.currentTarget.dataset.info;
    school.type='school';
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2]; //上一个页面
    //直接调用上一个页面的setData()方法，把数据存到上一个页面中去
    prevPage.setData({
      changeSchool: school,
      editType:'school'
    })
    wx.navigateBack({//返回
      delta: 1
    })
  },
  onReady:function(){
  },
  tabSelect(e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      MainCur: e.currentTarget.dataset.id,
      VerticalNavTop: (e.currentTarget.dataset.id - 1) * 50
    })
  },
  VerticalMain(e) {
    let that = this;
    let list = this.data.school;
    let tabHeight = 0;
    if (this.data.load) {
      for (let i = 0; i < list.length; i++) {
        let view = wx.createSelectorQuery().select("#main-" + i);
        console.log(list[i],'-----i')
        view.fields({
          size: true
        }, data => {
          list[i].top = tabHeight;
          tabHeight = tabHeight + data.height;
          list[i].bottom = tabHeight;     
        }).exec();
      }
      that.setData({
        load: false,
        school: list
      })
    }
    let scrollTop = e.detail.scrollTop + 20;
    for (let i = 0; i < list.length; i++) {
      if (scrollTop > list[i].top && scrollTop < list[i].bottom) {
        that.setData({
          VerticalNavTop: (list[i].id - 1) * 50,
          TabCur: list[i].id-1
        })
        return false
      }
    }
  }
})
